// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <PyMeshAttributes.h>
#include <ObserverToCallback.h>
#include <stdio.h>
#include <Py2and3Support.h>
#include <visit-config.h>
#include <ColorAttribute.h>
#include <ColorAttribute.h>
#include <GlyphTypes.h>

// ****************************************************************************
// Module: PyMeshAttributes
//
// Purpose:
//   Attributes for the mesh plot
//
// Note:       Autogenerated by xml2python. Do not modify by hand!
//
// Programmer: xml2python
// Creation:   omitted
//
// ****************************************************************************

//
// This struct contains the Python type information and a MeshAttributes.
//
struct MeshAttributesObject
{
    PyObject_HEAD
    MeshAttributes *data;
    bool        owns;
    PyObject   *parent;
};

//
// Internal prototypes
//
static PyObject *NewMeshAttributes(int);
std::string
PyMeshAttributes_ToString(const MeshAttributes *atts, const char *prefix, const bool forLogging)
{
    std::string str;
    char tmpStr[1000];

    if(atts->GetLegendFlag())
        snprintf(tmpStr, 1000, "%slegendFlag = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%slegendFlag = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%slineWidth = %d\n", prefix, atts->GetLineWidth());
    str += tmpStr;
    const unsigned char *meshColor = atts->GetMeshColor().GetColor();
    snprintf(tmpStr, 1000, "%smeshColor = (%d, %d, %d, %d)\n", prefix, int(meshColor[0]), int(meshColor[1]), int(meshColor[2]), int(meshColor[3]));
    str += tmpStr;
    const char *meshColorSource_names = "Foreground, MeshCustom, MeshRandom";
    switch (atts->GetMeshColorSource())
    {
      case MeshAttributes::Foreground:
          snprintf(tmpStr, 1000, "%smeshColorSource = %sForeground  # %s\n", prefix, prefix, meshColorSource_names);
          str += tmpStr;
          break;
      case MeshAttributes::MeshCustom:
          snprintf(tmpStr, 1000, "%smeshColorSource = %sMeshCustom  # %s\n", prefix, prefix, meshColorSource_names);
          str += tmpStr;
          break;
      case MeshAttributes::MeshRandom:
          snprintf(tmpStr, 1000, "%smeshColorSource = %sMeshRandom  # %s\n", prefix, prefix, meshColorSource_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    const char *opaqueColorSource_names = "Background, OpaqueCustom, OpaqueRandom";
    switch (atts->GetOpaqueColorSource())
    {
      case MeshAttributes::Background:
          snprintf(tmpStr, 1000, "%sopaqueColorSource = %sBackground  # %s\n", prefix, prefix, opaqueColorSource_names);
          str += tmpStr;
          break;
      case MeshAttributes::OpaqueCustom:
          snprintf(tmpStr, 1000, "%sopaqueColorSource = %sOpaqueCustom  # %s\n", prefix, prefix, opaqueColorSource_names);
          str += tmpStr;
          break;
      case MeshAttributes::OpaqueRandom:
          snprintf(tmpStr, 1000, "%sopaqueColorSource = %sOpaqueRandom  # %s\n", prefix, prefix, opaqueColorSource_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    const char *opaqueMode_names = "Auto, On, Off";
    switch (atts->GetOpaqueMode())
    {
      case MeshAttributes::Auto:
          snprintf(tmpStr, 1000, "%sopaqueMode = %sAuto  # %s\n", prefix, prefix, opaqueMode_names);
          str += tmpStr;
          break;
      case MeshAttributes::On:
          snprintf(tmpStr, 1000, "%sopaqueMode = %sOn  # %s\n", prefix, prefix, opaqueMode_names);
          str += tmpStr;
          break;
      case MeshAttributes::Off:
          snprintf(tmpStr, 1000, "%sopaqueMode = %sOff  # %s\n", prefix, prefix, opaqueMode_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    snprintf(tmpStr, 1000, "%spointSize = %g\n", prefix, atts->GetPointSize());
    str += tmpStr;
    const unsigned char *opaqueColor = atts->GetOpaqueColor().GetColor();
    snprintf(tmpStr, 1000, "%sopaqueColor = (%d, %d, %d, %d)\n", prefix, int(opaqueColor[0]), int(opaqueColor[1]), int(opaqueColor[2]), int(opaqueColor[3]));
    str += tmpStr;
    const char *smoothingLevel_names = "NONE, Fast, High";
    switch (atts->GetSmoothingLevel())
    {
      case MeshAttributes::None:
          snprintf(tmpStr, 1000, "%ssmoothingLevel = %sNONE  # %s\n", prefix, prefix, smoothingLevel_names);
          str += tmpStr;
          break;
      case MeshAttributes::Fast:
          snprintf(tmpStr, 1000, "%ssmoothingLevel = %sFast  # %s\n", prefix, prefix, smoothingLevel_names);
          str += tmpStr;
          break;
      case MeshAttributes::High:
          snprintf(tmpStr, 1000, "%ssmoothingLevel = %sHigh  # %s\n", prefix, prefix, smoothingLevel_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    if(atts->GetPointSizeVarEnabled())
        snprintf(tmpStr, 1000, "%spointSizeVarEnabled = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%spointSizeVarEnabled = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%spointSizeVar = \"%s\"\n", prefix, atts->GetPointSizeVar().c_str());
    str += tmpStr;
    const char *pointType_names = "Box, Axis, Icosahedron, Octahedron, Tetrahedron, "
        "SphereGeometry, Point, Sphere";
    switch (atts->GetPointType())
    {
      case Box:
          snprintf(tmpStr, 1000, "%spointType = %sBox  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      case Axis:
          snprintf(tmpStr, 1000, "%spointType = %sAxis  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      case Icosahedron:
          snprintf(tmpStr, 1000, "%spointType = %sIcosahedron  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      case Octahedron:
          snprintf(tmpStr, 1000, "%spointType = %sOctahedron  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      case Tetrahedron:
          snprintf(tmpStr, 1000, "%spointType = %sTetrahedron  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      case SphereGeometry:
          snprintf(tmpStr, 1000, "%spointType = %sSphereGeometry  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      case Point:
          snprintf(tmpStr, 1000, "%spointType = %sPoint  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      case Sphere:
          snprintf(tmpStr, 1000, "%spointType = %sSphere  # %s\n", prefix, prefix, pointType_names);
          str += tmpStr;
          break;
      default:
          break;
    }

    if(atts->GetShowInternal())
        snprintf(tmpStr, 1000, "%sshowInternal = 1\n", prefix);
    else
        snprintf(tmpStr, 1000, "%sshowInternal = 0\n", prefix);
    str += tmpStr;
    snprintf(tmpStr, 1000, "%spointSizePixels = %d\n", prefix, atts->GetPointSizePixels());
    str += tmpStr;
    snprintf(tmpStr, 1000, "%sopacity = %g\n", prefix, atts->GetOpacity());
    str += tmpStr;
    return str;
}

static PyObject *
MeshAttributes_Notify(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    obj->data->Notify();
    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_SetLegendFlag(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the legendFlag in the object.
    obj->data->SetLegendFlag(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetLegendFlag(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetLegendFlag()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MeshAttributes_SetLineWidth(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the lineWidth in the object.
    obj->data->SetLineWidth(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetLineWidth(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetLineWidth()));
    return retval;
}

/*static*/ PyObject *
MeshAttributes_SetMeshColor(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    int c[4];
    if(!PyArg_ParseTuple(args, "iiii", &c[0], &c[1], &c[2], &c[3]))
    {
        c[3] = 255;
        if(!PyArg_ParseTuple(args, "iii", &c[0], &c[1], &c[2]))
        {
            double dr, dg, db, da;
            if(PyArg_ParseTuple(args, "dddd", &dr, &dg, &db, &da))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = int(da);
            }
            else if(PyArg_ParseTuple(args, "ddd", &dr, &dg, &db))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = 255;
            }
            else
            {
                PyObject *tuple = NULL;
                if(!PyArg_ParseTuple(args, "O", &tuple))
                    return NULL;

                if(!PyTuple_Check(tuple))
                    return NULL;

                // Make sure that the tuple is the right size.
                if(PyTuple_Size(tuple) < 3 || PyTuple_Size(tuple) > 4)
                    return NULL;

                // Make sure that all elements in the tuple are ints.
                for(int i = 0; i < PyTuple_Size(tuple); ++i)
                {
                    PyObject *item = PyTuple_GET_ITEM(tuple, i);
                    if(PyInt_Check(item))
                        c[i] = int(PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, i)));
                    else if(PyFloat_Check(item))
                        c[i] = int(PyFloat_AS_DOUBLE(PyTuple_GET_ITEM(tuple, i)));
                    else
                        return NULL;
                }
            }
        }
        PyErr_Clear();
    }

    // Set the meshColor in the object.
    ColorAttribute ca(c[0], c[1], c[2], c[3]);
    obj->data->SetMeshColor(ca);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetMeshColor(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the meshColor.
    PyObject *retval = PyTuple_New(4);
    const unsigned char *meshColor = obj->data->GetMeshColor().GetColor();
    PyTuple_SET_ITEM(retval, 0, PyInt_FromLong(long(meshColor[0])));
    PyTuple_SET_ITEM(retval, 1, PyInt_FromLong(long(meshColor[1])));
    PyTuple_SET_ITEM(retval, 2, PyInt_FromLong(long(meshColor[2])));
    PyTuple_SET_ITEM(retval, 3, PyInt_FromLong(long(meshColor[3])));
    return retval;
}

/*static*/ PyObject *
MeshAttributes_SetMeshColorSource(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid meshColorSource value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Foreground";
        ss << ", MeshCustom";
        ss << ", MeshRandom";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the meshColorSource in the object.
    obj->data->SetMeshColorSource(MeshAttributes::MeshColor(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetMeshColorSource(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetMeshColorSource()));
    return retval;
}

/*static*/ PyObject *
MeshAttributes_SetOpaqueColorSource(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid opaqueColorSource value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Background";
        ss << ", OpaqueCustom";
        ss << ", OpaqueRandom";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the opaqueColorSource in the object.
    obj->data->SetOpaqueColorSource(MeshAttributes::OpaqueColor(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetOpaqueColorSource(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetOpaqueColorSource()));
    return retval;
}

/*static*/ PyObject *
MeshAttributes_SetOpaqueMode(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid opaqueMode value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " Auto";
        ss << ", On";
        ss << ", Off";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the opaqueMode in the object.
    obj->data->SetOpaqueMode(MeshAttributes::OpaqueMode(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetOpaqueMode(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetOpaqueMode()));
    return retval;
}

/*static*/ PyObject *
MeshAttributes_SetPointSize(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the pointSize in the object.
    obj->data->SetPointSize(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetPointSize(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetPointSize());
    return retval;
}

/*static*/ PyObject *
MeshAttributes_SetOpaqueColor(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    int c[4];
    if(!PyArg_ParseTuple(args, "iiii", &c[0], &c[1], &c[2], &c[3]))
    {
        c[3] = 255;
        if(!PyArg_ParseTuple(args, "iii", &c[0], &c[1], &c[2]))
        {
            double dr, dg, db, da;
            if(PyArg_ParseTuple(args, "dddd", &dr, &dg, &db, &da))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = int(da);
            }
            else if(PyArg_ParseTuple(args, "ddd", &dr, &dg, &db))
            {
                c[0] = int(dr);
                c[1] = int(dg);
                c[2] = int(db);
                c[3] = 255;
            }
            else
            {
                PyObject *tuple = NULL;
                if(!PyArg_ParseTuple(args, "O", &tuple))
                    return NULL;

                if(!PyTuple_Check(tuple))
                    return NULL;

                // Make sure that the tuple is the right size.
                if(PyTuple_Size(tuple) < 3 || PyTuple_Size(tuple) > 4)
                    return NULL;

                // Make sure that all elements in the tuple are ints.
                for(int i = 0; i < PyTuple_Size(tuple); ++i)
                {
                    PyObject *item = PyTuple_GET_ITEM(tuple, i);
                    if(PyInt_Check(item))
                        c[i] = int(PyInt_AS_LONG(PyTuple_GET_ITEM(tuple, i)));
                    else if(PyFloat_Check(item))
                        c[i] = int(PyFloat_AS_DOUBLE(PyTuple_GET_ITEM(tuple, i)));
                    else
                        return NULL;
                }
            }
        }
        PyErr_Clear();
    }

    // Set the opaqueColor in the object.
    ColorAttribute ca(c[0], c[1], c[2], c[3]);
    obj->data->SetOpaqueColor(ca);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetOpaqueColor(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    // Allocate a tuple the with enough entries to hold the opaqueColor.
    PyObject *retval = PyTuple_New(4);
    const unsigned char *opaqueColor = obj->data->GetOpaqueColor().GetColor();
    PyTuple_SET_ITEM(retval, 0, PyInt_FromLong(long(opaqueColor[0])));
    PyTuple_SET_ITEM(retval, 1, PyInt_FromLong(long(opaqueColor[1])));
    PyTuple_SET_ITEM(retval, 2, PyInt_FromLong(long(opaqueColor[2])));
    PyTuple_SET_ITEM(retval, 3, PyInt_FromLong(long(opaqueColor[3])));
    return retval;
}

/*static*/ PyObject *
MeshAttributes_SetSmoothingLevel(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if ((val == -1 && PyErr_Occurred()) || long(cval) != val)
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }

    if (cval < 0 || cval >= 3)
    {
        std::stringstream ss;
        ss << "An invalid smoothingLevel value was given." << std::endl;
        ss << "Valid values are in the range [0,2]." << std::endl;
        ss << "You can also use the following symbolic names:";
        ss << " None";
        ss << ", Fast";
        ss << ", High";
        return PyErr_Format(PyExc_ValueError, ss.str().c_str());
    }

    Py_XDECREF(packaged_args);

    // Set the smoothingLevel in the object.
    obj->data->SetSmoothingLevel(MeshAttributes::SmoothingLevel(cval));

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetSmoothingLevel(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetSmoothingLevel()));
    return retval;
}

/*static*/ PyObject *
MeshAttributes_SetPointSizeVarEnabled(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the pointSizeVarEnabled in the object.
    obj->data->SetPointSizeVarEnabled(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetPointSizeVarEnabled(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetPointSizeVarEnabled()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MeshAttributes_SetPointSizeVar(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged as first member of a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyUnicode_Check(packaged_args))
            args = packaged_args;
    }

    if (!PyUnicode_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a unicode string");
    }

    char const *val = PyUnicode_AsUTF8(args);
    std::string cval = std::string(val);

    if (val == 0 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as utf8 string");
    }

    Py_XDECREF(packaged_args);

    // Set the pointSizeVar in the object.
    obj->data->SetPointSizeVar(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetPointSizeVar(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    PyObject *retval = PyString_FromString(obj->data->GetPointSizeVar().c_str());
    return retval;
}

/*static*/ PyObject *
MeshAttributes_SetPointType(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    int ival = -999;
    if (PySequence_Check(args) && !PyArg_ParseTuple(args, "i", &ival))
        return PyErr_Format(PyExc_TypeError, "Expecting scalar integer arg");
    else if (PyNumber_Check(args) && (ival = (int) PyLong_AsLong(args)) == -1 && PyErr_Occurred())
        return PyErr_Format(PyExc_TypeError, "Expecting scalar integer arg");
    if (ival == -999)
        return PyErr_Format(PyExc_TypeError, "Expecting scalar integer arg");

    if(ival >= 0 && ival < 8)
    {
        obj->data->SetPointType(GlyphType(ival));
    }
    else
    {
        return PyErr_Format(PyExc_ValueError, "An invalid pointType value was given. "
                        "Valid values are in the range of [0,7]. "
                        "You can also use the following names: "
                        "Box, Axis, Icosahedron, Octahedron, Tetrahedron, "
                        "SphereGeometry, Point, Sphere.");
    }

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetPointType(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetPointType()));
    return retval;
}

/*static*/ PyObject *
MeshAttributes_SetShowInternal(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    bool cval = bool(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ bool");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ bool");
    }

    Py_XDECREF(packaged_args);

    // Set the showInternal in the object.
    obj->data->SetShowInternal(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetShowInternal(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(obj->data->GetShowInternal()?1L:0L);
    return retval;
}

/*static*/ PyObject *
MeshAttributes_SetPointSizePixels(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    long val = PyLong_AsLong(args);
    int cval = int(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ int");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(long(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ int");
    }

    Py_XDECREF(packaged_args);

    // Set the pointSizePixels in the object.
    obj->data->SetPointSizePixels(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetPointSizePixels(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    PyObject *retval = PyInt_FromLong(long(obj->data->GetPointSizePixels()));
    return retval;
}

/*static*/ PyObject *
MeshAttributes_SetOpacity(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;

    PyObject *packaged_args = 0;

    // Handle args packaged into a tuple of size one
    // if we think the unpackaged args matches our needs
    if (PySequence_Check(args) && PySequence_Size(args) == 1)
    {
        packaged_args = PySequence_GetItem(args, 0);
        if (PyNumber_Check(packaged_args))
            args = packaged_args;
    }

    if (PySequence_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "expecting a single number arg");
    }

    if (!PyNumber_Check(args))
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_TypeError, "arg is not a number type");
    }

    double val = PyFloat_AsDouble(args);
    double cval = double(val);

    if (val == -1 && PyErr_Occurred())
    {
        Py_XDECREF(packaged_args);
        PyErr_Clear();
        return PyErr_Format(PyExc_TypeError, "arg not interpretable as C++ double");
    }
    if (fabs(double(val))>1.5E-7 && fabs((double(double(cval))-double(val))/double(val))>1.5E-7)
    {
        Py_XDECREF(packaged_args);
        return PyErr_Format(PyExc_ValueError, "arg not interpretable as C++ double");
    }

    Py_XDECREF(packaged_args);

    // Set the opacity in the object.
    obj->data->SetOpacity(cval);

    Py_INCREF(Py_None);
    return Py_None;
}

/*static*/ PyObject *
MeshAttributes_GetOpacity(PyObject *self, PyObject *args)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)self;
    PyObject *retval = PyFloat_FromDouble(obj->data->GetOpacity());
    return retval;
}



PyMethodDef PyMeshAttributes_methods[MESHATTRIBUTES_NMETH] = {
    {"Notify", MeshAttributes_Notify, METH_VARARGS},
    {"SetLegendFlag", MeshAttributes_SetLegendFlag, METH_VARARGS},
    {"GetLegendFlag", MeshAttributes_GetLegendFlag, METH_VARARGS},
    {"SetLineWidth", MeshAttributes_SetLineWidth, METH_VARARGS},
    {"GetLineWidth", MeshAttributes_GetLineWidth, METH_VARARGS},
    {"SetMeshColor", MeshAttributes_SetMeshColor, METH_VARARGS},
    {"GetMeshColor", MeshAttributes_GetMeshColor, METH_VARARGS},
    {"SetMeshColorSource", MeshAttributes_SetMeshColorSource, METH_VARARGS},
    {"GetMeshColorSource", MeshAttributes_GetMeshColorSource, METH_VARARGS},
    {"SetOpaqueColorSource", MeshAttributes_SetOpaqueColorSource, METH_VARARGS},
    {"GetOpaqueColorSource", MeshAttributes_GetOpaqueColorSource, METH_VARARGS},
    {"SetOpaqueMode", MeshAttributes_SetOpaqueMode, METH_VARARGS},
    {"GetOpaqueMode", MeshAttributes_GetOpaqueMode, METH_VARARGS},
    {"SetPointSize", MeshAttributes_SetPointSize, METH_VARARGS},
    {"GetPointSize", MeshAttributes_GetPointSize, METH_VARARGS},
    {"SetOpaqueColor", MeshAttributes_SetOpaqueColor, METH_VARARGS},
    {"GetOpaqueColor", MeshAttributes_GetOpaqueColor, METH_VARARGS},
    {"SetSmoothingLevel", MeshAttributes_SetSmoothingLevel, METH_VARARGS},
    {"GetSmoothingLevel", MeshAttributes_GetSmoothingLevel, METH_VARARGS},
    {"SetPointSizeVarEnabled", MeshAttributes_SetPointSizeVarEnabled, METH_VARARGS},
    {"GetPointSizeVarEnabled", MeshAttributes_GetPointSizeVarEnabled, METH_VARARGS},
    {"SetPointSizeVar", MeshAttributes_SetPointSizeVar, METH_VARARGS},
    {"GetPointSizeVar", MeshAttributes_GetPointSizeVar, METH_VARARGS},
    {"SetPointType", MeshAttributes_SetPointType, METH_VARARGS},
    {"GetPointType", MeshAttributes_GetPointType, METH_VARARGS},
    {"SetShowInternal", MeshAttributes_SetShowInternal, METH_VARARGS},
    {"GetShowInternal", MeshAttributes_GetShowInternal, METH_VARARGS},
    {"SetPointSizePixels", MeshAttributes_SetPointSizePixels, METH_VARARGS},
    {"GetPointSizePixels", MeshAttributes_GetPointSizePixels, METH_VARARGS},
    {"SetOpacity", MeshAttributes_SetOpacity, METH_VARARGS},
    {"GetOpacity", MeshAttributes_GetOpacity, METH_VARARGS},
    {NULL, NULL}
};

//
// Type functions
//

static void
MeshAttributes_dealloc(PyObject *v)
{
   MeshAttributesObject *obj = (MeshAttributesObject *)v;
   if(obj->parent != 0)
       Py_DECREF(obj->parent);
   if(obj->owns)
       delete obj->data;
}

static PyObject *MeshAttributes_richcompare(PyObject *self, PyObject *other, int op);
PyObject *
PyMeshAttributes_getattr(PyObject *self, char *name)
{
    if(strcmp(name, "legendFlag") == 0)
        return MeshAttributes_GetLegendFlag(self, NULL);
    if(strcmp(name, "lineWidth") == 0)
        return MeshAttributes_GetLineWidth(self, NULL);
    if(strcmp(name, "meshColor") == 0)
        return MeshAttributes_GetMeshColor(self, NULL);
    if(strcmp(name, "meshColorSource") == 0)
        return MeshAttributes_GetMeshColorSource(self, NULL);
    if(strcmp(name, "Foreground") == 0)
        return PyInt_FromLong(long(MeshAttributes::Foreground));
    if(strcmp(name, "MeshCustom") == 0)
        return PyInt_FromLong(long(MeshAttributes::MeshCustom));
    if(strcmp(name, "MeshRandom") == 0)
        return PyInt_FromLong(long(MeshAttributes::MeshRandom));

    if(strcmp(name, "opaqueColorSource") == 0)
        return MeshAttributes_GetOpaqueColorSource(self, NULL);
    if(strcmp(name, "Background") == 0)
        return PyInt_FromLong(long(MeshAttributes::Background));
    if(strcmp(name, "OpaqueCustom") == 0)
        return PyInt_FromLong(long(MeshAttributes::OpaqueCustom));
    if(strcmp(name, "OpaqueRandom") == 0)
        return PyInt_FromLong(long(MeshAttributes::OpaqueRandom));

    if(strcmp(name, "opaqueMode") == 0)
        return MeshAttributes_GetOpaqueMode(self, NULL);
    if(strcmp(name, "Auto") == 0)
        return PyInt_FromLong(long(MeshAttributes::Auto));
    if(strcmp(name, "On") == 0)
        return PyInt_FromLong(long(MeshAttributes::On));
    if(strcmp(name, "Off") == 0)
        return PyInt_FromLong(long(MeshAttributes::Off));

    if(strcmp(name, "pointSize") == 0)
        return MeshAttributes_GetPointSize(self, NULL);
    if(strcmp(name, "opaqueColor") == 0)
        return MeshAttributes_GetOpaqueColor(self, NULL);
    if(strcmp(name, "smoothingLevel") == 0)
        return MeshAttributes_GetSmoothingLevel(self, NULL);
    if(strcmp(name, "None") == 0)
        return PyInt_FromLong(long(MeshAttributes::None));
    if(strcmp(name, "NONE") == 0)
        return PyInt_FromLong(long(MeshAttributes::None));
    if(strcmp(name, "Fast") == 0)
        return PyInt_FromLong(long(MeshAttributes::Fast));
    if(strcmp(name, "High") == 0)
        return PyInt_FromLong(long(MeshAttributes::High));

    if(strcmp(name, "pointSizeVarEnabled") == 0)
        return MeshAttributes_GetPointSizeVarEnabled(self, NULL);
    if(strcmp(name, "pointSizeVar") == 0)
        return MeshAttributes_GetPointSizeVar(self, NULL);
    if(strcmp(name, "pointType") == 0)
        return MeshAttributes_GetPointType(self, NULL);
    if(strcmp(name, "Box") == 0)
        return PyInt_FromLong(long(Box));
    if(strcmp(name, "Axis") == 0)
        return PyInt_FromLong(long(Axis));
    if(strcmp(name, "Icosahedron") == 0)
        return PyInt_FromLong(long(Icosahedron));
    if(strcmp(name, "Octahedron") == 0)
        return PyInt_FromLong(long(Octahedron));
    if(strcmp(name, "Tetrahedron") == 0)
        return PyInt_FromLong(long(Tetrahedron));
    if(strcmp(name, "SphereGeometry") == 0)
        return PyInt_FromLong(long(SphereGeometry));
    if(strcmp(name, "Point") == 0)
        return PyInt_FromLong(long(Point));
    if(strcmp(name, "Sphere") == 0)
        return PyInt_FromLong(long(Sphere));

    if(strcmp(name, "showInternal") == 0)
        return MeshAttributes_GetShowInternal(self, NULL);
    if(strcmp(name, "pointSizePixels") == 0)
        return MeshAttributes_GetPointSizePixels(self, NULL);
    if(strcmp(name, "opacity") == 0)
        return MeshAttributes_GetOpacity(self, NULL);


    // Add a __dict__ answer so that dir() works
    if (!strcmp(name, "__dict__"))
    {
        PyObject *result = PyDict_New();
        for (int i = 0; PyMeshAttributes_methods[i].ml_meth; i++)
            PyDict_SetItem(result,
                PyString_FromString(PyMeshAttributes_methods[i].ml_name),
                PyString_FromString(PyMeshAttributes_methods[i].ml_name));
        return result;
    }

    return Py_FindMethod(PyMeshAttributes_methods, self, name);
}

int
PyMeshAttributes_setattr(PyObject *self, char *name, PyObject *args)
{
    PyObject NULL_PY_OBJ;
    PyObject *obj = &NULL_PY_OBJ;

    if(strcmp(name, "legendFlag") == 0)
        obj = MeshAttributes_SetLegendFlag(self, args);
    else if(strcmp(name, "lineWidth") == 0)
        obj = MeshAttributes_SetLineWidth(self, args);
    else if(strcmp(name, "meshColor") == 0)
        obj = MeshAttributes_SetMeshColor(self, args);
    else if(strcmp(name, "meshColorSource") == 0)
        obj = MeshAttributes_SetMeshColorSource(self, args);
    else if(strcmp(name, "opaqueColorSource") == 0)
        obj = MeshAttributes_SetOpaqueColorSource(self, args);
    else if(strcmp(name, "opaqueMode") == 0)
        obj = MeshAttributes_SetOpaqueMode(self, args);
    else if(strcmp(name, "pointSize") == 0)
        obj = MeshAttributes_SetPointSize(self, args);
    else if(strcmp(name, "opaqueColor") == 0)
        obj = MeshAttributes_SetOpaqueColor(self, args);
    else if(strcmp(name, "smoothingLevel") == 0)
        obj = MeshAttributes_SetSmoothingLevel(self, args);
    else if(strcmp(name, "pointSizeVarEnabled") == 0)
        obj = MeshAttributes_SetPointSizeVarEnabled(self, args);
    else if(strcmp(name, "pointSizeVar") == 0)
        obj = MeshAttributes_SetPointSizeVar(self, args);
    else if(strcmp(name, "pointType") == 0)
        obj = MeshAttributes_SetPointType(self, args);
    else if(strcmp(name, "showInternal") == 0)
        obj = MeshAttributes_SetShowInternal(self, args);
    else if(strcmp(name, "pointSizePixels") == 0)
        obj = MeshAttributes_SetPointSizePixels(self, args);
    else if(strcmp(name, "opacity") == 0)
        obj = MeshAttributes_SetOpacity(self, args);

    if (obj != NULL && obj != &NULL_PY_OBJ)
        Py_DECREF(obj);

    if (obj == &NULL_PY_OBJ)
    {
        obj = NULL;
        PyErr_Format(PyExc_NameError, "name '%s' is not defined", name);
    }
    else if (obj == NULL && !PyErr_Occurred())
        PyErr_Format(PyExc_RuntimeError, "unknown problem with '%s'", name);

    return (obj != NULL) ? 0 : -1;
}

static int
MeshAttributes_print(PyObject *v, FILE *fp, int flags)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)v;
    fprintf(fp, "%s", PyMeshAttributes_ToString(obj->data, "",false).c_str());
    return 0;
}

PyObject *
MeshAttributes_str(PyObject *v)
{
    MeshAttributesObject *obj = (MeshAttributesObject *)v;
    return PyString_FromString(PyMeshAttributes_ToString(obj->data,"", false).c_str());
}

//
// The doc string for the class.
//
#if PY_MAJOR_VERSION > 2 || (PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION >= 5)
static const char *MeshAttributes_Purpose = "Attributes for the mesh plot";
#else
static char *MeshAttributes_Purpose = "Attributes for the mesh plot";
#endif

//
// Python Type Struct Def Macro from Py2and3Support.h
//
//         VISIT_PY_TYPE_OBJ( VPY_TYPE,
//                            VPY_NAME,
//                            VPY_OBJECT,
//                            VPY_DEALLOC,
//                            VPY_PRINT,
//                            VPY_GETATTR,
//                            VPY_SETATTR,
//                            VPY_STR,
//                            VPY_PURPOSE,
//                            VPY_RICHCOMP,
//                            VPY_AS_NUMBER)

//
// The type description structure
//

VISIT_PY_TYPE_OBJ(MeshAttributesType,         \
                  "MeshAttributes",           \
                  MeshAttributesObject,       \
                  MeshAttributes_dealloc,     \
                  MeshAttributes_print,       \
                  PyMeshAttributes_getattr,   \
                  PyMeshAttributes_setattr,   \
                  MeshAttributes_str,         \
                  MeshAttributes_Purpose,     \
                  MeshAttributes_richcompare, \
                  0); /* as_number*/

//
// Helper function for comparing.
//
static PyObject *
MeshAttributes_richcompare(PyObject *self, PyObject *other, int op)
{
    // only compare against the same type 
    if ( Py_TYPE(self) != &MeshAttributesType
         || Py_TYPE(other) != &MeshAttributesType)
    {
        Py_INCREF(Py_NotImplemented);
        return Py_NotImplemented;
    }

    PyObject *res = NULL;
    MeshAttributes *a = ((MeshAttributesObject *)self)->data;
    MeshAttributes *b = ((MeshAttributesObject *)other)->data;

    switch (op)
    {
       case Py_EQ:
           res = (*a == *b) ? Py_True : Py_False;
           break;
       case Py_NE:
           res = (*a != *b) ? Py_True : Py_False;
           break;
       default:
           res = Py_NotImplemented;
           break;
    }

    Py_INCREF(res);
    return res;
}

//
// Helper functions for object allocation.
//

static MeshAttributes *defaultAtts = 0;
static MeshAttributes *currentAtts = 0;

static PyObject *
NewMeshAttributes(int useCurrent)
{
    MeshAttributesObject *newObject;
    newObject = PyObject_NEW(MeshAttributesObject, &MeshAttributesType);
    if(newObject == NULL)
        return NULL;
    if(useCurrent && currentAtts != 0)
        newObject->data = new MeshAttributes(*currentAtts);
    else if(defaultAtts != 0)
        newObject->data = new MeshAttributes(*defaultAtts);
    else
        newObject->data = new MeshAttributes;
    newObject->owns = true;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

static PyObject *
WrapMeshAttributes(const MeshAttributes *attr)
{
    MeshAttributesObject *newObject;
    newObject = PyObject_NEW(MeshAttributesObject, &MeshAttributesType);
    if(newObject == NULL)
        return NULL;
    newObject->data = (MeshAttributes *)attr;
    newObject->owns = false;
    newObject->parent = 0;
    return (PyObject *)newObject;
}

///////////////////////////////////////////////////////////////////////////////
//
// Interface that is exposed to the VisIt module.
//
///////////////////////////////////////////////////////////////////////////////

PyObject *
MeshAttributes_new(PyObject *self, PyObject *args)
{
    int useCurrent = 0;
    if (!PyArg_ParseTuple(args, "i", &useCurrent))
    {
        if (!PyArg_ParseTuple(args, ""))
            return NULL;
        else
            PyErr_Clear();
    }

    return (PyObject *)NewMeshAttributes(useCurrent);
}

//
// Plugin method table. These methods are added to the visitmodule's methods.
//
static PyMethodDef MeshAttributesMethods[] = {
    {"MeshAttributes", MeshAttributes_new, METH_VARARGS},
    {NULL,      NULL}        /* Sentinel */
};

static Observer *MeshAttributesObserver = 0;

std::string
PyMeshAttributes_GetLogString()
{
    std::string s("MeshAtts = MeshAttributes()\n");
    if(currentAtts != 0)
        s += PyMeshAttributes_ToString(currentAtts, "MeshAtts.", true);
    return s;
}

static void
PyMeshAttributes_CallLogRoutine(Subject *subj, void *data)
{
    typedef void (*logCallback)(const std::string &);
    logCallback cb = (logCallback)data;

    if(cb != 0)
    {
        std::string s("MeshAtts = MeshAttributes()\n");
        s += PyMeshAttributes_ToString(currentAtts, "MeshAtts.", true);
        cb(s);
    }
}

void
PyMeshAttributes_StartUp(MeshAttributes *subj, void *data)
{
    if(subj == 0)
        return;

    currentAtts = subj;
    PyMeshAttributes_SetDefaults(subj);

    //
    // Create the observer that will be notified when the attributes change.
    //
    if(MeshAttributesObserver == 0)
    {
        MeshAttributesObserver = new ObserverToCallback(subj,
            PyMeshAttributes_CallLogRoutine, (void *)data);
    }

}

void
PyMeshAttributes_CloseDown()
{
    delete defaultAtts;
    defaultAtts = 0;
    delete MeshAttributesObserver;
    MeshAttributesObserver = 0;
}

PyMethodDef *
PyMeshAttributes_GetMethodTable(int *nMethods)
{
    *nMethods = 1;
    return MeshAttributesMethods;
}

bool
PyMeshAttributes_Check(PyObject *obj)
{
    return (obj->ob_type == &MeshAttributesType);
}

MeshAttributes *
PyMeshAttributes_FromPyObject(PyObject *obj)
{
    MeshAttributesObject *obj2 = (MeshAttributesObject *)obj;
    return obj2->data;
}

PyObject *
PyMeshAttributes_New()
{
    return NewMeshAttributes(0);
}

PyObject *
PyMeshAttributes_Wrap(const MeshAttributes *attr)
{
    return WrapMeshAttributes(attr);
}

void
PyMeshAttributes_SetParent(PyObject *obj, PyObject *parent)
{
    MeshAttributesObject *obj2 = (MeshAttributesObject *)obj;
    obj2->parent = parent;
}

void
PyMeshAttributes_SetDefaults(const MeshAttributes *atts)
{
    if(defaultAtts)
        delete defaultAtts;

    defaultAtts = new MeshAttributes(*atts);
}

